/**
 * Created by lenovo on 2015/12/3.
 */
/**
 *  关闭文件的写法
 * */
var fs = require("fs");
function openAndWriteToSystemLog(writeBuffer, callback) {
    fs.open("./my_file", "a", function opened(err, fd) {
        if (err) {
            return callback(err);
        }
        function notifyError(err) {
            fs.close(fd, function () {
                callback(err);
            });
        }

        var bufferOffset = 0,
            bufferLength = writeBuffer.length,
            filePosition = null;
        fs.write(fd, writeBuffer, bufferOffset, bufferLength, filePosition, function wrote(err, written) {
            if (err) {
                return notifyError(err)
            }
            fs.close(fd, function () {
                callback(err);
            });
        });
    });
}

openAndWriteToSystemLog(new Buffer("writing this string"), function done(err) {
    if (err) {
        console.log("error!");
        return;
    }
    console.log("all charater is no errors!");
})